package com.example.zsf.base;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class Presenter {
    public interface PresenterListener<T>{
        void onSuccess(T object);
        void onError(String error);
    }

    public static class SampleCallback implements Callback {
        PresenterListener presenterListener;

        public SampleCallback(PresenterListener presenterListener) {
            this.presenterListener = presenterListener;
        }

        @Override
        public void onResponse(Call call, Response response) {
            if (presenterListener == null) {
                return;
            }
            if (response.body() == null){
                return;
            }
            presenterListener.onSuccess(response.body());
        }

        @Override
        public void onFailure(Call call, Throwable t) {
            if (presenterListener == null) {
                return;
            }
            presenterListener.onError(t.getMessage());
        }
    }
}
